package com.ml.carManager.ui.my;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.content.ContextCompat;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.jaeger.library.StatusBarUtil;
import com.ml.carManager.R;
import com.ml.carManager.net.NetProxyListener;
import com.ml.carManager.ui.dialog.SimpleHintDialog;
import com.ml.carManager.ui.dialog.WaitDialog;
import com.ml.carManager.ui.dialog.listener.OnEnterClickListener;
import com.ml.carManager.ui.login.LoginActivity;
import com.ml.carManager.utils.auth.AuthManager;
import com.ml.carManager.utils.map.AMapUtil;
import com.ml.carManager.utils.map.Location;
import com.ml.carManager.utils.map.LocationUtils;

import org.jetbrains.annotations.NotNull;

import butterknife.BindView;
import custom.base.entity.base.BaseResponse;
import custom.base.log.MLog;
import custom.base.ui.activity.AppManager;
import custom.base.ui.activity.BaseActivity;
import retrofit2.Call;

public class MapActivity extends BaseActivity {
    @BindView(R.id.act_map_location)
    AppCompatButton btnExitLogin;
    @BindView(R.id.act_map_mapview)
    MapView mapView;


    private AMap aMap;

    private WaitDialog waitDialog;

    @Override
    public boolean initStatusBar() {
        StatusBarUtil.setColor(getActivity(), ContextCompat.getColor(getActivity(), R.color.app_main_color), 0);
        return false;
    }

    @Override
    public int getLayoutID() {
        return R.layout.act_map;
    }

    @Override
    public void initView(@NonNull @NotNull Bundle savedInstanceState) {
        super.initView(savedInstanceState);

        /*
         * 设置离线地图存储目录，在下载离线地图或初始化地图设置;
         * 使用过程中可自行设置, 若自行设置了离线地图存储的路径，
         * 则需要在离线地图下载和使用地图页面都进行路径设置
         * */
        //Demo中为了其他界面可以使用下载的离线地图，使用默认位置存储，屏蔽了自定义设置
        //  MapsInitializer.sdcardDir =OffLineMapUtils.getSdCacheDir(this);
        mapView.onCreate(savedInstanceState);// 此方法必须重写
        if (aMap == null) {
            aMap = mapView.getMap();
        }

        waitDialog = new WaitDialog(getActivity());
    }


    @Override
    public void initListener() {
        super.initListener();
        btnExitLogin.setOnClickListener(this);

        LocationUtils.getInstance(getApplicationContext()).addLocationListener(new LocationUtils.OnLocationListener() {
            @Override
            public void onLocationFinish(Location location) {
                MLog.test(location);
                AMapUtil.animateCamera(aMap, location.getLat(), location.getLng(), 15, 1000);
            }
        });
    }


    @Override
    public void onClick(View v, int clickID) {
        if (clickID == btnExitLogin.getId()) {
            LocationUtils.getInstance(getApplicationContext()).requestLocated(getActivity());

        }
    }

    @Override
    protected void onDestroy() {
        LocationUtils.getInstance(getApplicationContext()).stopLocation();
//        LocationUtils.getInstance(getApplicationContext()).removeLocation(this);
        super.onDestroy();
    }


}
